<?php  // $Id: view.php, 2010/09/04 afterlastangel Exp $

/**
 * This page lists all the instances of studentcp in a particular course
 *
 * @author  Le Kien Truc <afterlastangel@gmail.com>
 * @version $Id: view.php, 2010/09/04 $
 * @package mod/studentcp
 */


/// (Replace studentcp with the name of your module and remove this line)

require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/locallib.php');

$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
$a  = optional_param('a', 0, PARAM_INT);  // studentcp instance ID

if ($id) {
    if (! $cm = get_coursemodule_from_id('studentcp', $id)) {
        error('Course Module ID was incorrect');
    }

    if (! $course = get_record('course', 'id', $cm->course)) {
        error('Course is misconfigured');
    }

    if (! $studentcp = get_record('studentcp', 'id', $cm->instance)) {
        error('Course module is incorrect');
    }

} else if ($a) {
    if (! $studentcp = get_record('studentcp', 'id', $a)) {
        error('Course module is incorrect');
    }
    if (! $course = get_record('course', 'id', $studentcp->course)) {
        error('Course is misconfigured');
    }
    if (! $cm = get_coursemodule_from_instance('studentcp', $studentcp->id, $course->id)) {
        error('Course Module ID was incorrect');
    }

} else {
    error('You must specify a course_module ID or an instance ID');
}

require_login($course, true, $cm);

add_to_log($course->id, "studentcp", "view", "view.php?id=$cm->id", "$studentcp->id");

/// Print the page header
$strstudentcps = get_string('modulenameplural', 'studeget_stringntcp');
$strstudentcp  = get_string('modulename', 'studentcp');

$navlinks = array();
$navlinks[] = array('name' => $strstudentcps, 'link' => "index.php?id=$course->id", 'type' => 'activity');
$navlinks[] = array('name' => format_string($studentcp->name), 'link' => '', 'type' => 'activityinstance');

$navigation = build_navigation($navlinks);

print_header_simple(format_string($studentcp->name), '', $navigation, '', '', true,
              update_module_button($cm->id, $course->id, $strstudentcp), navmenu($course, $cm));

/// Print the main part of the page
show_tabs($cm, $context, 'schedule');
unset($table);

        $table->head[] = get_string('day', 'studentcp');
        $table->align[] = 'left';
        $table->size[] = '';
        $table->wrap[2] = 'nowrap';
        for ($jj=2;$jj<=8;$jj++) {
            $table->head[] = get_string("thu$jj", 'studentcp');
            $table->align[] = 'center';
            $table->size[] = '';
        }
        $table->data[0][] = get_string('date','studentcp');
        for ($jj=1;$jj<=7;$jj++)
        {
            $table->data[0][] = date("d/m",mktime(0, 0, 0, date("m")  , date("d")+$jj-date("N"), date("Y")));
        }
        //So tiet hoc cua mot thoi khoa bieu, co the cau hinh thoi gian.
        for ($i=1;$i<=$sessioncount;$i++)
        {
            for ($jj=1;$jj<=7;$jj++)
                {
                    $table->data[0][] = date("d/m",mktime(0, 0, 0, date("m")  , date("d")+$jj-date("N"), date("Y")));
                }
        }
        
        //mktime(0, 0, 0, date("m")  , date("d")+1, date("Y"));
        //$table->data[1][] = week_day(8, 2009, 30, 1);
print_table($table);

/// Finish the page
print_footer($course);

?>
